# coding:utf-8
'html out put'


class HtmlOutputer(object):
    def __init__(self):
        self.datas = []

    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)

    def output_html(self):
        fout = open('output.html', 'w', encoding='utf-8')

        fout.write("<html>")

        fout.write("<head>")
        fout.write("<meta %s>" % 'http-equiv = "Content-Type" content = "text/html;charset=UTF-8"')
        fout.write("</head>")

        fout.write("<h2>")
        fout.write('小雨每日知道')
        fout.write("</h2>")
        fout.write("<body>")
        fout.write("<table>")

        for data in self.datas:
            fout.write("<tr>")
            fout.write("<td>%s</td>" % data['periodical'])
            print(data['periodical'])
            fout.write("<td>%s</td>" % data['date'])
            print(data['date'])
            fout.write("<td>%s</td>" % str(data['content']))
            fout.write("</tr>")

        fout.write("</table>")
        fout.write("</body>")
        fout.write("</html>")

        fout.close()
